
//招聘登记
EPS.employ={
    d:{},
    i:function(){
        this.page.i();
        this.btn.i();
    },
    time:{
        ai:function(){
            var today=new Date().Format('yyyy-MM-dd');
            var start={
                format:'YYYY-MM-DD hh:mm',
                zIndex:12345678,
                minDate:today+' 00:00:00',
                okfun:function(v){
                    end.minDate =v.date['YYYY']+'-'+v.date['MM']+'-'+v.date['DD']+' 00:00:00';
                    endDates();
                }
            };
            var end={
                format:'YYYY-MM-DD hh:mm',
                zIndex:12345678,
                minDate:today+' 00:00:00',
                okfun:function(v){
                    start.maxDate=v.date['YYYY']+'-'+v.date['MM']+'-'+v.date['DD']+' 00:00:00';
                }
            };
            function endDates() {
                //end.trigger = false;
                $.jeDate('[name="interviewerTime"]',end);
            }
            $.jeDate('[name="contactTime"]',start);
            $.jeDate('[name="interviewerTime"]',end);
        }
    },
    page:{
        i:function(){
            this.loadTable();
            JsForm().skin();
        },
        loadTable:function(){
            EPS.employ.d.eTable=JsTable('.mod-table').render({
                height:'full-200',
                limit:20,
                fixed:'left',
                checkbox:true,
                map:{
                    name:'userInfo.name'
                },
                cols:[
                    {field:'name',title:'姓名',width:100},
                    {field:'phone',title:'联系电话',width:110},
                    {field:'job',title:'应聘岗位',width:110},
                    {field:'department',title:'面试部门',width:100},
                    {field:'interviewer',title:'面试官',width:100},
                    {field:'interviewerTime',title:'面试时间',width:140},
                    {field:'interview',title:'面试地点',width:150},
                    {field:'state',title:'当前状态',width:100,align:'center',className:'employ-state',fun:function(key){
                        return key[0]['status']
                    }},
                    {field:'contactTime',title:'联系时间',width:120},
                    {field:'sms',title:'发送短信提醒',align:'center',width:120,fun:function(key,idx){return key==1?'已发送':'<a href="javascript:EPS.employ.btn.sendSMS('+idx+');" class="btn btn-small btn-rounded btn-green">发送短信</a>'}},
                    {field:'sendTime',title:'发送时间',width:155}
                ],
                staticData:epsData.employ
            });
        }
    },
    btn:{
        i:function(){
            this.stateList();
        },
        addInterview:function(){
            var ly=layer.open({
                title:'添加面试约定',
                content:fui.$("#addInterview").html(),
                btn:['保存','继续添加','取消'],
                skin:'tips-1',
                resize:!1,
                yes:function(){
                    JsForm('.addInterviewForm').submit(function(r){
                        if(r.code==1){
                            epsData.addInterview(r.result,function(){
                                layer.close(ly);
                                layer.msg('添加成功');
                                EPS.employ.d.eTable.reload();
                            })
                        }else{
                            layer.msg(r.msg)
                        }
                    },1);
                },
                btn2:function(){
                    JsForm('.addInterviewForm').submit(function(r){
                        if(r.code==1){
                            epsData.addInterview(r.result,function(){
                                layer.msg('添加成功');
                                EPS.employ.d.eTable.reload();
                                fui.$('.tips-1').find('.layer-content').empty().append(fui.$("#addInterview").html())
                            })
                        }else{
                            layer.msg(r.msg)
                        }
                    },1);
                    return false;
                }
            });
            EPS.employ.time.ai();
        },
        InterviewRecords:function(){
            EPS.employ.d.eTable.checkBack(function(ck,cp){
                if(ck.length==0) return layer.msg('请先勾选');
                var nd={
                    ids:JSON.stringify(cp[0]),
                    names:cp[1].join(','),
                    phones:cp[2].join(','),
                    genders:cp[3].join(','),
                    contactTimes:cp[4].join(',')
                };
                nd.department=fui.array.same(cp[5]);
                nd.job=fui.array.same(cp[6]);
                nd.interviewer=fui.array.same(cp[7]);
                var ly=layer.open({
                    title:'面试记录',
                    content:JsTpl().render(nd,'interviewRecords'),
                    btn:['保存','取消'],
                    resize:!1,
                    skin:'tips-1',
                    yes:function(){
                        JsForm('.interviewRecordsForm').submit(function(r){
                            if(r.code==1){
                                layer.close(ly);
                                layer.msg('面试记录修改成功');
                                EPS.employ.d.eTable.reload();
                            }else{
                                layer.msg(r.msg)
                            }
                        })
                    }
                });
                JsForm('.interviewRecordsForm').render();
            },['id','userInfo.name','phone','userInfo.sex','contactTime','department','job','interviewer']);
        },
        delEmploy:function(){
            EPS.employ.d.eTable.checkBack(function(ck,cp){
                if(ck.length==0) return layer.msg('请先勾选');
                var ly=layer.open({
                    title:'删除',
                    content:'确认删除此记录？',
                    skin:'tips-ts',
                    btn:['确定','取消'],
                    yes:function(){
                        layer.close(ly);
                        console.log('需要删除的id数组'+cp[0]);
                        layer.msg('删除成功');
                        EPS.employ.d.eTable.reload();
                    }
                });
            },'id')
        },
        sendSMS:function(idx){
            EPS.employ.d.eTable.dataBack(idx,function(r){
                var oText=r.name+'您好，您与方阵人才预约'+r.interviewerTime+'面试，地点在'+r.interview+'，岗位为'+r.job+'，敬请按时赴约。 \n 欢迎关注人事云，助力企业发展，http://www.eyuangong.com/ehr.apk';
                var cText=r.interviewer+'您好，人事部预约'+r.interviewerTime+'面试'+r.job+'岗位'+r.name+'，请提前做好准备。';
                var ly=layer.open({
                    title:'发送短信',
                    content:JsTpl().render(r,'sendSMS'),
                    btn:['确定发送'],
                    skin:'tips-2',
                    yes:function(){
                        var nj={id:r.id};
                        if(!fui.$('#ssh-1').prop('checked')&&!fui.$('#ssh-2').prop('checked')) return layer.msg('没有选择需要发送的对象');
                        fui.$('#ssh-1').prop('checked')?nj.applicant=fui.$('.sendSMSBox [name="applicant"').val():'';
                        fui.$('#ssh-2').prop('checked')?nj.interviewer=fui.$('.sendSMSBox [name="interviewer"').val():'';
                        console.log('提交数据到后台'+JSON.stringify(nj));
                        layer.close(ly);
                        layer.open({
                            title:'提示',
                            content:'发送成功',
                            skin:'tips-ts'
                        })
                    }
                });
                fui.$('.sendSMSBox [name="applicant"').val(oText);
                fui.$('.sendSMSBox [name="interviewer"').val(cText)
            });
        },
        batchSMS:function(){
            EPS.employ.d.eTable.checkBack(function(ck,cp){
                if(ck.length==0) return layer.msg('请先勾选');
                if(ck.length==1){
                    ck=ck[0];
                    var oText=ck.name+'您好，您与方阵人才预约'+ck.interviewerTime+'面试，地点在'+ck.interview+'，岗位为'+ck.job+'，敬请按时赴约。 \n 欢迎关注人事云，助力企业发展，http://www.eyuangong.com/ehr.apk';
                    var cText=ck.interviewer+'您好，人事部预约'+ck.interviewerTime+'面试'+ck.job+'岗位'+ck.name+'，请提前做好准备。';
                    var ly=layer.open({
                        title:'发送短信',
                        content:JsTpl().render(ck,'sendSMS'),
                        btn:['确定发送'],
                        skin:'tips-2',
                        yes:function(){
                            var nj={id:ck.id};
                            if(!fui.$('#ssh-1').prop('checked')&&!fui.$('#ssh-2').prop('checked')) return layer.msg('没有选择需要发送的对象');
                            fui.$('#ssh-1').prop('checked')?nj.applicant=fui.$('.sendSMSBox [name="applicant"').val():'';
                            fui.$('#ssh-2').prop('checked')?nj.interviewer=fui.$('.sendSMSBox [name="interviewer"').val():'';
                            console.log('提交数据到后台'+JSON.stringify(nj));
                            layer.close(ly);
                            layer.open({
                                title:'提示',
                                content:'发送成功',
                                skin:'tips-ts'
                            })
                        }
                    });
                    fui.$('.sendSMSBox [name="applicant"').val(oText);
                    fui.$('.sendSMSBox [name="interviewer"').val(cText)
                }else{
                    var ly2=layer.open({
                        title:'批量发送短信',
                        content:fui.$('#sendSMS').html(),
                        skin:'tips-2',
                        btn:['确定发送'],
                        yes:function(){
                            var nj={id:JSON.stringify(cp[0])};
                            if(!fui.$('#ssh-1').prop('checked')&&!fui.$('#ssh-2').prop('checked')) return layer.msg('没有选择需要发送的对象');
                            fui.$('#ssh-1').prop('checked')?nj.applicant=fui.$('.sendSMSBox [name="applicant"').val():'';
                            fui.$('#ssh-2').prop('checked')?nj.interviewer=fui.$('.sendSMSBox [name="interviewer"').val():'';
                            console.log('提交数据到后台'+JSON.stringify(nj));
                            layer.close(ly2);
                            layer.open({
                                title:'提示',
                                content:'发送成功',
                                skin:'tips-ts'
                            })
                        }
                    })
                }
            },'id');
        },
        stateList:function(){
            var body=fui.$('body');
            body.on('mouseenter','.fui-td-employ-state',function(){
                var _t=fui.$(this),idx=_t.parent().index();
                EPS.employ.d.eTable.dataBack(idx,function(db){
                    var list=db.state;
                    _t.append('<div>123</div>')
                })
            }).on('mouseleave','.fui-td-employ-state',function(){
                //console.log('321');
            })
        }
    }
};
